<template>
  <div id="pie" style="height: 400px;">

  </div>
</template>
<script setup lang="ts">
import * as echarts from "echarts"
import { onMounted, ref } from "vue";
import { getHomePage } from '@/request/homePage/index';
/**
 * 存储请求到的图形数据
 */
let salePie = ref();
async function getEcharts() {
  // 发起请求
  let EchartsData = await getHomePage();
  // 将请求到的数据添加到动态数据中
  salePie.value = EchartsData.data.data.salePie;
  console.log(salePie.value);
}
//  调用请求图形数据方法
getEcharts();

onMounted(() => {
  let myChartDom = document.getElementById("pie")
  console.log(myChartDom);
  let myCharts = echarts.init(myChartDom!)
  window.onresize = function () {
    myCharts.resize();
  };
  console.log(myCharts);
  var option;
  option = {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
    series: [
      {
        name: '分类',
        type: 'pie',
        radius: ['40%', '70%'],
        center: ['30%', '45%'],  //设置圆心
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: '40',
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1048, name: 'Search Engine' },
          { value: 735, name: 'Direct' },
          { value: 580, name: 'Email' },
          { value: 484, name: 'Union Ads' },
          { value: 300, name: 'Video Ads' }
        ]
      }
    ]
  };
  myCharts.setOption(option)
})

</script>